<?php

# database connection
include '../lib5/pdoExt.php';
include 'dbConn.php';

# objlib library code
include '../lib5/Util.php';
include '../lib5/Object.php';
include '../lib5/JoinerRelation.php';
include '../lib5/SortedJoinerRelation.php';
include '../lib5/KeyRelation.php';
include '../lib5/SortedKeyRelation.php';
include '../lib5/Query.php';
include '../lib5/Node.php';


# englopya library code
foreach (glob ('../Classes/*.php') as $componentFile) {
        include_once ($componentFile);
}

foreach (glob ('../Classes/Component/*.php') as $componentFile) {
        include_once ($componentFile);
}

# englopya Relations
foreach (glob ('../Classes/Relations/*.php') as $relationFile) {
        include_once ($relationFile);
}

$dbh->exec ('drop table Nav');
$dbh->exec ('drop table NavHasNav');
$dbh->exec ('delete from Template where title = "Navigation Template 1"');

$navTempl = new Template (false, 'Navigation Template 1');
$navTempl->content = <<<TEMPL
<?php foreach (\$this->children as \$child) { ?>
<a href="/index.php/<?php echo \$child->URL ?>"><?php echo \$child->title ?></a><br>
<?php }; ?>
TEMPL;
$navTempl->save();

$style = new Style (false, 'Style1');

$rootNav = new Nav (false, false, array (
	'title'      => 'MainNav',
	'URL'        => 'Nav1',
	'templateId' => $navTempl->id,
	'styleId'    => $style->id
));
$rootNav->save();

$page = new Page (false, 'FirstPage');
$article = new Article (false, 'FirstArticle');

$subNav = new Nav (false, false, array (
	'title'      => 'SubNav1',
	'URL'        => 'SubNav1',
	'templateId' => $navTempl->id,
	'styleId'    => $style->id
));
$subNav->assignComponent ($page);
$subNav->save ();

$rootNav->assignChild ( $subNav );

$subNav = new Nav (false, false, array (
	'title'      => 'SubNav2',
	'URL'        => 'SubNav2',
	'templateId' => $navTempl->id,
	'styleId'    => $style->id
));
$subNav->assignComponent ($article);
$subNav->save ();

$rootNav->assignChild ( $subNav );

$rootNav->render ();

?>